<?php
include ('checkLogin.php');
$course_id = $_GET['course_id'];
$course_name = $_GET['course_name'];
$date_arr = array();
$sql = "select distinct day from attends where course_id='$course_id'";
$query = mysqli_query($cn, $sql);
while ($line=mysqli_fetch_assoc($query)) {
    array_push($date_arr, $line['day']);
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $course_name?> 的签到情况</title>
    <link rel="stylesheet" href="bootstrap/bootstrap.css">
</head>
<body style="background: #414057;">
<div class=".container">
    <center>
        <div class="well" style="width: 80%;">
            <div class="row">

                <center>
                    <div class="text-info"><?php echo $course_name;?></div>
                </center>
                <center>
                    <table class="table table-bordered" style="width: 90%;">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <?php
                            foreach ($date_arr as $day) {
                                $parsed = substr($day, 5);
                                $parsed = str_replace('-', '/', $parsed);
                                echo "<th>$parsed</th>";
                            }
                            ?>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $sql = "select id,real_name, day from userinfo natural join takes natural join attends where course_id='$course_id' order by id asc,day asc";
                        $query = mysqli_query($cn, $sql);
                        $currName = '';
                        $i = 0;
                        $day_size = count($date_arr);
                        while ($line=mysqli_fetch_assoc($query)) {
                            $name = $line['real_name'];
                            if ($name != $currName) {
                                if ($currName != '') {
                                    while ($i < $day_size) {
                                        echo "<td>✘1</td>";
                                        $i++;
                                    }
                                    echo "</tr>";
                                }
                                $i = 0;
                                echo "<tr><td>".$name."</td>";
                                $currName = $name;
                            }
                            $day = $line['day'];
                            while ($date_arr[$i] != $day && $i < $day_size) {
                                echo "<td>✘2</td>";
                                $i++;
                            }
                            echo "<td>✔️</td>";
                            $i++;

                        }
                        ?>
                        </tbody>
                    </table>
                </center>
            </div>
        </div>
    </center>
</div>

<script src="bootstrap/jquery-3.2.0.min.js"></script>
<script src="bootstrap/bootstrap.js"></script>
<script type="text/javascript">

</script>
</body>
</html>